//
//  HBScrollViewEmptyBaseView.m
//  HBLibary
//
//  Created by Rambo on 2018/6/6.
//

#import "HBScrollViewEmptyBaseView.h"
#import "UIView+HBFrame.h"

@implementation HBScrollViewEmptyBaseView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self prepare];
        
    }
    return self;
}

- (void)prepare{
    self.autoresizingMask = UIViewAutoresizingFlexibleWidth |  UIViewAutoresizingFlexibleHeight;
}

- (void)emptyBaseView_layoutSubviews{
    //    NSLog(@"%s",__func__);
}

- (void)willMoveToSuperview:(UIView *)newSuperview{
    [super willMoveToSuperview:newSuperview];
    
    //不是UIScrollView，不做操作
    //    if (newSuperview && ![newSuperview isKindOfClass:[UIScrollView class]]) return;
    //    [self layoutIfNeeded];
    //    if (newSuperview) {
    //        self.hb_width = newSuperview.hb_width;
    //        self.hb_height = newSuperview.hb_height;
    //    }
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    [self emptyBaseView_layoutSubviews];
}

/**
 创建emptyView
 
 @param image 图片
 @param title 标题
 @param detail 描述
 @param buttonTitle 按钮标题
 @param action 按钮点击回调
 @return emptyView
 */
+ (instancetype)emptyWithImage:(UIImage*)image title:(NSString*)title detail:(NSString*)detail buttonTitle:(NSString*)buttonTitle buttonActionTapBlock:(HBScrollViewEmptyBaseViewTapBlock)action{
    HBScrollViewEmptyBaseView *emptyView = [[self alloc] init];
    [emptyView emptyWithImage:image title:title detail:detail buttonTitle:buttonTitle buttonTarget:nil buttonAction:nil viewTarger:nil viewAction:nil buttonActionBlock:action viewTapBlock:nil];
    return emptyView;
}


/**
 创建emptyView
 
 @param image 图片
 @param title 标题
 @param detail 描述
 @param buttonTitle 按钮标题
 @param target 监听按钮点击对象
 @param action 监听按钮点击对象执行的方法
 @return emptyView
 */
+ (instancetype)emptyWithImage:(UIImage*)image title:(NSString*)title detail:(NSString*)detail buttonTitle:(NSString *)buttonTitle target:(id)target action:(SEL)action{
    HBScrollViewEmptyBaseView *emptyView = [[self alloc] init];
    [emptyView emptyWithImage:image title:title detail:detail buttonTitle:buttonTitle buttonTarget:target buttonAction:action viewTarger:nil viewAction:nil buttonActionBlock:nil viewTapBlock:nil];
    return emptyView;
}


/**
 创建emptyView
 
 @param image 图片
 @param title 标题
 @param detail 描述
 @param emptyViewTapBlock 触摸emptyView
 @return emptyView
 */
+ (instancetype)emptyWithImage:(UIImage*)image title:(NSString*)title detail:(NSString*)detail  emptyViewTapBlock:(HBScrollViewEmptyBaseViewTapBlock)emptyViewTapBlock{
    HBScrollViewEmptyBaseView *emptyView = [[self alloc] init];
    [emptyView emptyWithImage:image title:title detail:detail buttonTitle:nil buttonTarget:nil buttonAction:nil viewTarger:nil viewAction:nil buttonActionBlock:nil viewTapBlock:emptyViewTapBlock];
    return emptyView;
}

/**
 创建emptyView
 
 @param image 图片
 @param title 标题
 @param detail 描述
 @param target 监听emptyView点击对象
 @param sel 监听emptyView点击对象执行的方法
 @return emptyView
 */
+ (instancetype)emptyWithImage:(UIImage*)image title:(NSString*)title detail:(NSString*)detail target:(id)target action:(SEL)action{
    HBScrollViewEmptyBaseView *emptyView = [[self alloc] init];
    [emptyView emptyWithImage:image title:title detail:detail buttonTitle:nil buttonTarget:nil buttonAction:nil viewTarger:target viewAction:action buttonActionBlock:nil viewTapBlock:nil];
    return emptyView;
}

/**
 自定义emptyView
 
 @param costomView 自定义emptyView
 @return emptyView
 */
+ (instancetype)emptyWithCostomView:(UIView*)costomView{
    HBScrollViewEmptyBaseView *emptyView = [[self alloc] init];
    [emptyView emptyWithCostomView:costomView];
    return emptyView;
}

- (void)emptyWithImage:(UIImage*)image title:(NSString*)title detail:(NSString*)detail buttonTitle:(NSString*)buttonTitle buttonTarget:(id)buttonTarget buttonAction:(SEL)buttonAction viewTarger:(id)viewTarger viewAction:(SEL)viewAction buttonActionBlock:(HBScrollViewEmptyBaseViewTapBlock)buttonActionBlock  viewTapBlock:(HBScrollViewEmptyBaseViewTapBlock)viewTapBlock{
    _image = image;
    _title = title;
    _detail = detail;
    _buttonTitle = buttonTitle;
    _buttonTarget = buttonTarget;
    _buttonAction = buttonAction;
    _viewTarget = viewTarger;
    _viewAction = viewAction;
    _buttonActionBlock = buttonActionBlock;
    _viewTapBlock = viewTapBlock;
    
    if (!_contentView) {
        _contentView = [[UIView alloc] initWithFrame:CGRectZero];
        [self addSubview:_contentView];
    }
    
}

- (void)emptyWithCostomView:(UIView*)customView{
    
    //内容物背景视图
    if (!_contentView) {
        _contentView = [[UIView alloc] initWithFrame:CGRectZero];
        [self addSubview:_contentView];
    }
    
    if (!_customView) {
        [_contentView addSubview:customView];
    }
    _customView = customView;
    
}

- (void)setTitle:(NSString *)title{
    _title = title;
    [self emptyBaseView_layoutSubviews];
}

- (void)setDetail:(NSString *)detail{
    _detail = detail;
    [self emptyBaseView_layoutSubviews];
}

- (void)setImage:(UIImage *)image{
    _image = image;
    [self emptyBaseView_layoutSubviews];
}

- (void)setButtonTitle:(NSString *)buttonTitle{
    _buttonTitle = buttonTitle;
    [self emptyBaseView_layoutSubviews];
}

@end
